#include "AnimatedBird.h"

#include "variables.h"
#include "Transform.h"
#include <glm/glm.hpp>

AnimatedBird::AnimatedBird(void)
{
}


AnimatedBird::~AnimatedBird(void)
{
}

void AnimatedBird::draw(glm::mat4 global_transform){
		  glLoadIdentity();

		  float angle = ((float)(animate%1000))*.36;
		  glm::mat4 transf = Transform::translate(2,0,0)* (mat4(Transform::rotate( angle, vec3(0,0,1)))) *(this->transform);
		  glm::mat4 matx = glm::transpose( (transf)*(global_transform));
		  glLoadMatrixf(&matx[0][0]);

		  glUniform4fv(ambientcol ,1, this->ambient);
		  glUniform4fv(diffusecol ,1, this->diffuse );
		  glUniform4fv(specularcol ,1, this->specular );
		  glUniform4fv( emissioncol ,1, this->emission);
		  glUniform1f(shininesscol, this->shininess);

		  glm::vec3 norm = glm::cross( glm::vec3(0,.7,0), glm::vec3(-.2,.5,.3));
		  glNormal3f( norm[0],norm[1],norm[2]);
		  glBegin(GL_TRIANGLES);
				glVertex3f(0,0,0);
				glVertex3f(-.2,.5,.3);
				glVertex3f(0,.7,0);
		  glEnd();

		  norm = glm::cross( glm::vec3(0,.7,0), glm::vec3(.2,.5,.3));
		  glNormal3f( norm[0],norm[1],norm[2]);
		  glBegin(GL_TRIANGLES);
				glVertex3f(0,0,0);
				glVertex3f(0,.7,0);
				glVertex3f(.2,.5,.3);
		  glEnd();

		  float ztipcoord = -.2 + glm::abs(((float)(animate%100))-50.0)/100.0; 
		  norm = glm::cross( glm::vec3(-.4,-.3, ztipcoord), glm::vec3(-.2,.5,.3));
		  glNormal3f( norm[0],norm[1],norm[2]);
		  glBegin(GL_TRIANGLES);
				glVertex3f(0,0,0);
				glVertex3f(-.4,-.3, ztipcoord);
				glVertex3f(-.2,.5,.3);
		  glEnd();

		  norm = glm::cross( glm::vec3(.4,-.3, ztipcoord), glm::vec3(.2,.5,.3));
		  glNormal3f( norm[0],norm[1],norm[2]);
		  glBegin(GL_TRIANGLES);
				glVertex3f(0,0,0);
				glVertex3f(.4,-.3, ztipcoord);
				glVertex3f(.2,.5,.3);
		  glEnd();
}